def info():
    num = input("请输入nq：")
    n = int(num[0])
    q = int(num[-1])
    list_an = list()
    list_ti = list()
    for i in range(1, n + 1):
        a = input("请输入题目和答案  用空格分开：")
        list_num = a.split(" ")
        list_an.append(list_num)
    for j in range(1, q + 1):
        b = input("请输入题目和选择项  用空格分开：")
        list_num2 = b.split(" ")
        list_ti.append(list_num2)
    for re in range(0, q):
        ind1 = list_ti[re]
        for an_num in ind1:
            if list_an[re][1] == an_num:
                abcd = list_ti[re].index(an_num)
                if abcd == 1:
                    print("A")
                elif abcd == 2:
                    print("B")
                elif abcd == 3:
                    print("C")
                elif abcd == 4:
                    print("D")


if __name__ == '__main__':
    info()
    pass
